package service

import (
	"gorm.io/gorm"
	"srv/config"
	"srv/internal/model/dao"
)

func Count(eventsid, goodSpecId int) int64 {
	var value dao.LsSeckillSpecValue
	var total int64
	config.DB.Where("seckill_events_id=? AND good_spec_value_id=?", eventsid, goodSpecId).Find(&value).Count(&total)
	return total
}
func Counts(minPrice, maxPrice float64) int64 {
	var values dao.LsSeckillSpecValue
	var totals int64
	config.DB.Where("seckillPrice Between ? And ?", minPrice, maxPrice).Find(&values).Count(&totals)
	return totals
}
func Paginate(page, pageSize int) func(db *gorm.DB) *gorm.DB {
	return func(db *gorm.DB) *gorm.DB {
		switch {
		case pageSize > 100:
			pageSize = 100
		case pageSize <= 0:
			pageSize = 10
		}

		offset := (page - 1) * pageSize
		return db.Offset(offset).Limit(pageSize)
	}
}
